//*************************************************************************************
/** \file task_temphumid.h
 *    This file contains a task which periodically reads a Sensirion SHT15 
 *    temperature and humidity sensor. The sensors can take rather a long time to
 *    read, so it's a good idea to read them only as often as necessary.
 *
 *  States in Task:
 *    \li 0 - Read temperature: Gets temperature data from SHT15 and saves it
 *    \li 1 - Read humidity: Gets humidity data from SHT15 and saves it
 *
 *  Revisions:
 *    \li 12-27-07 JRR Original file
 *    \li 12-30-07 JRR Actually made the thing work and spelled Fahrenheit right
 *    \li 06-01-08 JRR Changed serial stuff to use base_text_serial and descendents
 */
//*************************************************************************************

/// This define prevents this file from being included more than once in a *.cc file
#ifndef _TASK_TEMPHUMID_H_
#define _TASK_TEMPHUMID_H_

#include "stl_task.h"


/** This definition is used to choose whether to use Celsius or Fahrenheit for 
 *  temperature readings. */
#define USE_FAHRENHEIT


//-------------------------------------------------------------------------------------
/** This class contains a task which reads a DS1822 temperature sensor periodically
 *  and makes the latest or average readings available to other tasks, such as a task
 *  which transmits the information periodically over a radio link. 
 */

class task_temphumid : public stl_task
    {
    protected:
        base_text_serial* the_debug_port;   ///< Pointer to a radio/serial port
        avr_sht15* the_sensor;              ///< Pointer to a SHT15 temp/humid sensor
        unsigned int current_temp;          ///< Current temperature in degrees F or C
        unsigned char current_humid;        ///< Current relative humidity in percent

    public:
        // The constructor creates a new task object
        task_temphumid (avr_sht15*, task_timer&, time_stamp);

        // The run method is where the task actually performs its function
        char run (char);
        
        // This method returns the latest temperature reading
        unsigned int get_latest_temperature (void);

        // This method returns the most recent humidity reading
        unsigned char get_latest_humidity (void);
    };

#endif // _TASK_TEMPHUMID_H_
